package cn.edu.scnu.controller;

import cn.edu.scnu.Service.BookService;
import cn.edu.scnu.entity.Return;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {
    @Autowired
    private BookService bookService;

    /**
     * 查询全部数据，但不带分页
     * @return
     */
    @GetMapping("/all")
    public Return getAll(){
        return bookService.findAll();
    }

    /**
     * 查询分页数据
     * @param currentPage
     * @param size
     * @return
     */
    @GetMapping("/page")
    public Return getPage(@RequestParam int currentPage, int size, String category, String bookName){
        return bookService.getPage(currentPage, size, category, bookName);
    }

    /**
     * 查询图书种类
     * @return
     */
    @GetMapping("/getCategory")
    public Return getCategory(){
        return bookService.getCategory();
    }

    /**
     * 根据图书种类查到图书
     * @param category
     * @return
     */
    @GetMapping("/bookCategory")
    public Return getBookByCategory(@RequestParam String category){
        return bookService.getByCategory(category);
    }

    @GetMapping("/ByBookId")
    public Return getByBookId(@RequestParam String bookId){
        System.out.println(bookId);
        return bookService.getBookById(bookId);
    }

    @GetMapping("/search")
    public Return getByBookName(@RequestParam int currentPage, int size, String bookName){
        return bookService.getBookByBookName(currentPage, size, bookName);
    }

}
